<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>小飞象-会员中心-商品管理</title>
  <link rel="stylesheet" href="//at.alicdn.com/t/font_810097_mgs6xzz1oj.css">
  <link rel="stylesheet" href="css/common/reset.css">
  <link rel="stylesheet" href="layui/css/layui.css">
  <link rel="stylesheet" href="css/reset-layui.css">
  <link rel="stylesheet" href="css/header.css">
  <link rel="stylesheet" href="css/common/nav.css">
  <link rel="stylesheet" href="css/common/aside.css">
  <link rel="stylesheet" href="css/common/content.css">
  <link rel="stylesheet" href="css/goods.min.css">
</head>

<body>
  <header>
    <div class="wrapper">
      <div class="clearfix headerBox">
        <h1 class="fl logo">
          <a href="">小飞象</a>
        </h1>
        <!-- <div class="fl alipayName">支付宝充值账号: <b class="redColor">156****8656</b>开户人: <b class="redColor">陈小窝</b></div> -->
        <div class="fr logOut">退出</div>
        <div class="fr userName"></div>
      </div>
    </div>
  </header>
  <div class="mhNav">
    <ul class="navMenuBox">
      <li>
        <a href="index.html">
          飞象首页
        </a>
      </li>
      <li class="memberUser">
        <a href="javascript:;" class="active">
          会员中心
        </a>
        <ul class="mhColumnSide">
          <li>
            <a href="member/basicInfo.html">基本资料</a>
          </li>
          <li>
            <a href="member/storeMage.html">店铺管理</a>
          </li>
          <li>
            <a href="member/readjustNum.html">调整单量</a>
          </li>
          <li>
            <a href="goodsMage.html">商品管理</a>
          </li>
        </ul>
      </li>
      <li>
        <a href="javascript:;">
          计划管理
          <!-- <i class="iconfont icon-arrow-up mhArrowIcon"></i>
                    <i class="iconfont icon-arrow-down mhArrowIcon"></i> -->
        </a>
        <ul class="mhColumnSide">
          <li>
            <a href="plan/newPlan.html">新建计划</a>
          </li>
          <li>
            <a href="plan/planMage.html">计划管理</a>
          </li>
        </ul>
      </li>
      <li>
        <a href="javascript:;">
          订单管理
          <!-- <i class="iconfont icon-arrow-up mhArrowIcon"></i>
                    <i class="iconfont icon-arrow-down mhArrowIcon"></i> -->
        </a>
        <ul class="mhColumnSide">
          <li>
            <a href="order/orderMage.html">订单管理</a>
          </li>
        </ul>
      </li>
      <li>
        <a href="javascript:;">
          资金管理
          <!-- <i class="iconfont icon-arrow-up mhArrowIcon"></i>
                    <i class="iconfont icon-arrow-down mhArrowIcon"></i> -->
        </a>
        <ul class="mhColumnSide">
          <li>
            <a href="capital/inAccout.html">账号充值</a>
          </li>
          <li>
            <a href="capital/transferMage.html">转账管理</a>
          </li>
          <li>
            <a href="capital/orderMage/dailyTaskDes.html">订单信息</a>
          </li>
          <li>
            <a href="capital/expressForm.html">获取快递底单</a>
          </li>
        </ul>
      </li>
      <li>
        <a href="">在线客服</a>
      </li>
    </ul>
  </div>
  <div class="clearfix wrapper mainBomContent">
    <!-- 会员中心-基本资料 -->
    <div class="asideMenu">
      <h2 class="title">
        <i class="iconfont icon--"></i> 会员中心
      </h2>
      <ul>
        <li>
          <a href="member/basicInfo.html">基本资料</a>
        </li>
        <li>
          <a href="member/storeMage.html">店铺管理</a>
        </li>
        <li>
          <a href="member/readjustNum.html">调整单量</a>
        </li>
        <li class="active">
          <a href="goodsMage.html">商品管理</a>
        </li>
      </ul>
    </div>
    <div class="rightContent">
      <div class="goodsMageView">
        <!-- <div class="addGoodsStep">
          <h2>添加商品步骤：</h2>
          <ul class="stepBox">
            <li><em>1</em>添加商品</li>
            <li><em>2</em>设置目标客户</li>
            <li><em>3</em>设置购买行为</li>
          </ul>
        </div> -->
        <div class="delGoods" id="delPrompt">
          <form class="layui-form">
            <p class="title">
              提示
            </p>
            <ul>
              <li class="" id="lblRemark"></li>
              <li>
                <input type="button" id="delGood" value="确定" class="selectBtn">
                <input type="button" value="取消" class="closeBtn">
              </li>
            </ul>
          </form>
        </div>
        <div class="selectGoods">
          <form class="layui-form" lay-filter="goodsFilter">
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">店铺：</label>
                <div class="layui-input-inline" style="width: 200px;">
                  <select id="shopNames">
                  </select>
                </div>
                <div class="layui-input-inline" style="width: 180px;">
                  <input type="text" name="price_max" placeholder="简称/名称" autocomplete="off" class="layui-input" id="goodsInfo">
                </div>
                <div class="layui-input-inline" style="width: 180px;">
                  <input type="text" name="price_max" placeholder="商品ID" autocomplete="off" class="layui-input" id="goodsNum">
                </div>
                <div class="layui-input-inline" style="width: 120px;">
                  <button class="layui-btn selectBtn" lay-submit lay-filter="selectGoods">查询</button>
                </div>
                <div class="layui-input-inline" style="width: 120px;">
                  <button type="reset" class="layui-btn layui-btn-primary refreshBtn" lay-submit lay-filter="refreshGoods">刷新</button>
                </div>
              </div>
            </div>
            <div class="layui-form-item goodsOptions">
              <div class="layui-inline" style="width:auto;">
                <a class="layui-btn selectBtn" href="addGoods.html" target="_bank">添加</a>
              </div>
              <div class="layui-inline" style="width:auto;">
                <button class="layui-btn selectBtn" type="button" id="EditGoods">编辑</button>
              </div>
              <div class="layui-inline" style="width:auto;">
                <button class="layui-btn selectBtn" type="button" id="delGoods">删除</button>
              </div>
              <div class="layui-inline" style="width:auto;">
                <button class="layui-btn selectBtn" type="button" id="targetCus">目标客户</button>
              </div>
              <div class="layui-inline" style="width:auto;">
                <button class="layui-btn selectBtn" id="buyWay" type="button">购买行为</button>
              </div>
              <div class="layui-inline" style="width:auto;">
                <button class="layui-btn selectBtn" type="button" id="seeDetail">查看详情</button>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="errorbox" id="clientValidation">
                <p id="clientValidationOL"></p>
              </div>
            </div>
          </form>
          <table class="layui-table">
            <colgroup>
              <col width="70">
              <col width="252">
              <col width="450">
              <col>
            </colgroup>
            <thead>
              <tr>
                <th><input type="checkbox" title="写作" id="All"></th>
                <th>简称</th>
                <th>商品名称</th>
              </tr>
            </thead>
            <tbody class="goodsLists">
              <!-- <tr>
                <td><input type="checkbox" title="写作"></td>
                <td>新品大理石瓷砖</td>
                <td>
                  <p class="goodsName">
                    简约柔光砖全瓷大理石瓷砖800x800 灰色地板砖餐厅客厅地砖防滑砖
                  </p>
                </td>
                <td>正常</td>
              </tr>
              <tr>
                <td><input type="checkbox" title="写作"></td>
                <td>新品大理石瓷砖</td>
                <td>
                  <p class="goodsName">
                    简约柔光砖全瓷大理石瓷砖800x800 灰色地板砖餐厅客厅地砖防滑砖
                  </p>
                </td>
                <td>正常</td>
              </tr>
              <tr>
                <td><input type="checkbox" title="写作"></td>
                <td>新品大理石瓷砖</td>
                <td>
                  <p class="goodsName">
                    简约柔光砖全瓷大理石瓷砖800x800 灰色地板砖餐厅客厅地砖防滑砖
                  </p>
                </td>
                <td>正常</td>
              </tr>
              <tr>
                <td><input type="checkbox" title="写作"></td>
                <td>新品大理石瓷砖</td>
                <td>
                  <p class="goodsName">
                    简约柔光砖全瓷大理石瓷砖800x800 灰色地板砖餐厅客厅地砖防滑砖
                  </p>
                </td>
                <td>正常</td>
              </tr>
              <tr>
                <td><input type="checkbox" title="写作"></td>
                <td>新品大理石瓷砖</td>
                <td>
                  <p class="goodsName">
                    简约柔光砖全瓷大理石瓷砖800x800 灰色地板砖餐厅客厅地砖防滑砖
                  </p>
                </td>
                <td>正常</td>
              </tr> -->
            </tbody>
          </table>
          <div class="loadMore">
            <button id="loadMore">加载更多</button>
          </div>
        </div>
      </div>
    </div>
  </div>
  <script src="js/jquery.min.js"></script>
  <script src="layui/layui.js"></script>
  <script src="js/jquery.cookie.js"></script>
  <script src="js/dataRequest.js"></script>
  <script>
    var mid = $.cookie('id');
    if (!mid) {
      window.location.href = "/login.html";
    }
    $(".mhNav .navMenuBox > li > a").click(function (event) {
      if ($(this).siblings('ul').is(':visible')) {
        $(this).siblings('ul').stop(true, true).slideUp();
        $(this).removeClass('active')
      } else {
        $(this).siblings('ul').stop(true, true).slideDown().parents('li').siblings().find('ul').stop(true, true).slideUp();
        $(this).addClass('active').parents('li').siblings().find('a').removeClass('active');
      }
    });
    $("#All").click(function () {
      if ($(this).attr("checked") == "checked") {
        $("input[type='checkbox']").attr("checked", true);
      } else {
        $("input[type='checkbox']").attr("checked", false);
      }
    });
    layui.use(['jquery', 'form', 'upload'], function () {
      var $ = layui.jquery,
        form = layui.form,
        layer = layui.layer,
        pageNum = 1;
      $.ajax({
        type: "GET",
        url: BASE_URL + MAP_URL + 'shop/merchants/' + mid,
        dataType: 'json',
        contentType: "application/json;charset=utf-8",
        success: function (data) {
          // console.log("请求数据为", data.data)
          var shopNameText = "";
          if (data.data == null || !data.data) {
            layer.msg('数据出错,请重新登录', {
              icon: 5,
              time: 6000,
              end: function () {
                location.href = '/login.html';
              }
            });
          } else {
            // console.log("----------------------------")
            for (var i = 0; i < data.data.length; i++) {
              shopNameText += '<option value="">请选择</option>';
              shopNameText += '<option value=' + data.data[i].id + '>' + data.data[i].shopName +
                '</option>';
            }
            $("#shopNames").html(shopNameText);
            layui.form.render('select', 'goodsFilter');
            // console.log("shopNames", shopNameText);
            $(".userName").html(data.data.loginId);
          }
        },
      });
      $.ajax({
        type: "get",
        url: "http://47.92.174.143:8888/v1/client/merchants/" + mid,
        dataType: 'json',
        success: function (data) {
          // console.log("请求数据为", data.data)
          // 存储总额
          if (data.data == null || !data.data) {
            layer.msg('数据出错,请重新登录', {
              icon: 5,
              time: 6000,
              end: function () {
                location.href = '/login.html';
              }
            });
          } else {
            $(".userName").html(data.data.loginId);
          }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) { }
      });
      // 商品列表展示
      goodsLists();
      // 商品管理筛选
      form.on('submit(selectGoods)', function (data) {
        $(".goodsLists").html("");
        pageNum = 1;
        goodsLists();
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
      });
      // 商品管理刷新
      form.on('submit(refreshGoods)', function (data) {
        $(".goodsLists").html("");
        pageNum = 1;
        var shopId = $("#shopNames option:selected").val("");
        console.log("你是我的店铺id", shopId)
        var goodsInfo = $("#goodsInfo").val("");
        var goodsNum = $("#goodsNum").val("");
        goodsLists();
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
      });
      // 加载更多
      $("#loadMore").on("click", function () {
        loadMoreData();
      })
      function goodsLists() {
        var shopId = $("#shopNames option:selected").val();
        console.log("你是我的店铺id", shopId)
        var goodsInfo = $("#goodsInfo").val();
        var goodsNum = $("#goodsNum").val();
        var JdateJson = {};
        if (shopId != "") {
          JdateJson.shopId = shopId;
        }
        if (goodsInfo != "") {
          JdateJson.goodsInfo = goodsInfo;
        }
        if (goodsNum != "") {
          JdateJson.goodsNum = goodsNum;
        }
        console.log("json", JdateJson);
        // JdateJson = {
        //   "shopId": shopId,
        //   "goodsInfo": goodsInfo,
        //   "goodsNum": goodsNum
        // }
        // return;
        $.ajax({
          type: "GET",
          url: BASE_URL + MAP_URL
            + "goods/list/" + pageNum + '/10/?merchantsId=' + mid,
          dataType: 'json',
          // contentType: "application/json;charset=utf-8",
          data: JdateJson,
          success: function (data) {
            console.log("查询数据为", data.data)
            // 存储总额
            if (data.data == null || !data.data) {
              layer.msg('数据出错,请重新登录', {
                icon: 5,
                time: 6000,
                end: function () {
                  location.href = '/login.html';
                }
              });
            } else {
              // $(".goodsLists").html("");
              if (data.data.list.length == 0) {
                console.log(123);
                $("#loadMore").parent().addClass("noload");
                $("#loadMore").attr("disabled", true);
                $("#loadMore").html("没有数据拉");
                $("#loadMore").css("cursor", "not-allowed");
              } else {
                $("#loadMore").parent().removeClass("noload");
                $("#loadMore").attr("disabled", false);
                $("#loadMore").html("加载更多");
                $("#loadMore").css("cursor", "pointer");
              }
              var str = "";
              for (var i = 0; i < data.data.list.length; i++) {
                // console.log("进来了么")
                str += '<tr>';
                str += '<td><input type="checkbox" data-id=' + i + ' value="' + data.data.list[i].id + '"></td>';
                str += '<td>' + data.data.list[i].goodsInfo
                '</td>';
                str += '<td>';
                str += '<p class="goodsName">';
                str += '' + data.data.list[i].goodsName + '';
                str += '</p>';
                str += '</td>';
                str += '</tr>';
              }
              $(".goodsLists").append(str);
              $("#EditGoods").on("click", function () {
                EditGoods();
              });
              $("#delGoods").on("click", function () {
                deleteGood();
              });
              $("#seeDetail").on("click", function () {
                seeDetail();
              });
              $("#buyWay").on("click", function () {
                buyWay();
              });
              $("#targetCus").on("click", function () {
                TargetCus();
              });
              function EditGoods() {
                if (CheckSelect()) {
                  var goodsId = $("td input[type='checkbox']:checked").attr("data-id");
                  console.log("goodsId++++", goodsId);
                  $.cookie("goodsInfo", JSON.stringify(data.data.list[goodsId]));
                  // console.log($.cookie("goodsInfo"));
                  // return;
                  window.open("editGoods.html");
                  // $(location).attr("href", "editGoods.html");
                  // window.location.href = "editGoods.html";
                }
              }
              function TargetCus() {
                if (CheckSelect()) {
                  var goodsId = $("td input[type='checkbox']:checked").val();
                  console.log("goodsId++++", goodsId);
                  $.cookie("goodsInfo", JSON.stringify(data.data.list[goodsId]));
                  layer.open({
                    type: 2 //此处以iframe举例
                    ,
                    title: '目标客户',
                    area: ['700px', '650px'],
                    shadeClose: true //开启遮罩关闭
                    ,
                    offset: 'auto',
                    scrollbar: true,
                    content: ['/plan/newPlan/addTarget.html'],
                    success: function (layero, index) {
                      var iframe = window['layui-layer-iframe' + index];
                      iframe.child(goodsId);
                    },
                    zIndex: layer.zIndex //重点1
                  });
                }
              }
              function buyWay() {
                if (CheckSelect()) {
                  var goodsId = $("td input[type='checkbox']:checked").val();
                  console.log("goodsId++++", goodsId);
                  $.cookie("buygoodsId", goodsId);
                  $.cookie("goodsInfo", JSON.stringify(data.data.list[goodsId]));
                  layer.open({
                    type: 2 //此处以iframe举例
                    ,
                    title: '买号购买行为',
                    area: ['900px', '520px'],
                    shadeClose: true //开启遮罩关闭
                    ,
                    offset: 'auto',
                    scrollbar: true,
                    content: ['/buyway.html'],
                    // success: function (layero, index) {
                    //   var iframe = window['layui-layer-iframe' + index];
                    //   iframe.child(goodsId);
                    // },
                    zIndex: layer.zIndex //重点1
                  });
                }
              }
              function deleteGood() {
                if (CheckSelect()) {
                  var goodsId = $("td input[type='checkbox']:checked").val();
                  $(".delGoods").show();
                  var selectLength = $("td input[type='checkbox']:checked").length;
                  var name = $("td input[type='checkbox']:checked").attr("name");
                  $("#lblRemark").html("是否对选中的<span style='font-weight:bolder;font-size:16px;color:red'>" + selectLength + "个</span>商品执行【删除】操作？</br></br>删除后商品将在前台隐藏，如需恢复请重新添加商品。");
                  $("#delGood").on("click", function () {
                    delGoodsDate(goodsId);
                  });
                }
              }
              function delGoodsDate(goodsId) {
                $.ajax(
                  {
                    type: "DELETE",
                    url: BASE_URL + MAP_URL + 'goods/' + goodsId,
                    dataType: "json",
                    error: function (XmlHttpRequest, textStatus, errorThrown) {
                      var $errorPage = XmlHttpRequest.responseText;
                      $("<li>" + $errorPage + "</li>").appendTo($("#clientValidationOL"));
                      $("#clientValidation").show();
                    },
                    success: function (data) {
                      if (data.code == "200") {
                        window.location.reload();
                        return;
                      }
                    }
                  });
              }
              function seeDetail() {
                if (CheckSelect()) {
                  var goodsId = $("td input[type='checkbox']:checked").val();
                  // window.open('goodsDetInfo.html?id=' + goodsId);
                  location.href = 'goodsDetInfo.html?id=' + goodsId;
                }
              }
              function CheckSelect() {
                $("#clientValidationOL").html("");
                $("#clientValidation").hide();
                var selectLength = $("td input[type='checkbox']:checked").length;
                if (selectLength != 1) {
                  $("<li>请选择一条数据</li>").appendTo($("#clientValidationOL"));
                  $("#clientValidation").show();
                  return false;
                }
                return true;
              }
            }
          },
          error: function (XMLHttpRequest, textStatus, errorThrown) { }
        });
      }
      function loadMoreData() {
        pageNum++;
        goodsLists();
      }
      $(".closeBtn").on("click", function () {
        closePop();
      });
      $(".delGoods").on("click", function () {
        closePop();
      });
      function closePop() {
        $(".delGoods").hide();
      }
    });
  </script>
</body>

</html>